﻿Imports System.Data.SqlClient

Public Class clsPedidosDetalle

    Private mintIdPedidoDetalle As Integer
    Private mintIdPedido As Integer
    Private mstrCodigo As String
    Private mstrProducto As String
    Private mdblExistencia As Double
    Private mdblMaximo As Double
    Private mdblMinimo As Double
    Private mdblMedia As Double
    Private mdblPedir As Double
    Private mstrObservaciones As String
    Private mintEnviar As Integer
    Public Property IdPedidoDetalle() As Integer
        Get
            Return mintIdPedidoDetalle
        End Get
        Set(ByVal value As Integer)
            mintIdPedidoDetalle = value
        End Set
    End Property
   
    Public Property IdPedido() As Integer
        Get
            Return mintIdPedido
        End Get
        Set(ByVal value As Integer)
            mintIdPedido = value
        End Set
    End Property
    Public Property Codigo() As String
        Get
            Return mstrCodigo
        End Get
        Set(ByVal value As String)
            mstrCodigo = value
        End Set
    End Property
    Public Property Producto() As String
        Get
            Return mstrProducto
        End Get
        Set(ByVal value As String)
            mstrProducto = value
        End Set
    End Property
    Public Property Existencia() As Double
        Get
            Return mdblExistencia
        End Get
        Set(ByVal value As Double)
            mdblExistencia = value
        End Set
    End Property
    Public Property Maximo() As Double
        Get
            Return mdblMaximo
        End Get
        Set(ByVal value As Double)
            mdblMaximo = value
        End Set
    End Property
    Public Property Minimo() As Double
        Get
            Return mdblMinimo
        End Get
        Set(ByVal value As Double)
            mdblMinimo = value
        End Set
    End Property
    Public Property Media() As Double
        Get
            Return mdblMedia
        End Get
        Set(ByVal value As Double)
            mdblMedia = value
        End Set
    End Property

    Public Property Pedir() As Double
        Get
            Return mdblPedir
        End Get
        Set(ByVal value As Double)
            mdblPedir = value
        End Set
    End Property
    Public Property Observaciones As String
        Get
            Return mstrObservaciones
        End Get
        Set(ByVal value As String)
            mstrObservaciones = value
        End Set
    End Property
    Public Property Enviar() As Double
        Get
            Return mintEnviar
        End Get
        Set(ByVal value As Double)
            mintEnviar = value
        End Set
    End Property
    Public Sub New()
        mintIdPedidoDetalle = 0
        mintIdPedido = 0
        mstrCodigo = ""
        mstrProducto = ""
        mdblExistencia = 0
        mdblMaximo = 0
        mdblMinimo = 0
        mdblMedia = 0
        mdblPedir = 0
        mstrObservaciones = ""
        mintEnviar = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into PedidosDetalle (" & _
                            "IdPedido," & _
                            "Codigo," & _
                            "Producto," & _
                            "Existencia," & _
                            "Maximo," & _
                            "Minimo," & _
                            "Media," & _
                            "Pedir," & _
                            "Observaciones," & _
                            "Enviar)" & _
                            "VALUES (" & _
                            "@IdPedido," & _
                            "@Codigo," & _
                            "@Producto," & _
                            "@Existencia," & _
                            "@Maximo," & _
                            "@Minimo," & _
                            "@Media," & _
                            "@Pedir," & _
                            "@Observaciones," & _
                            "@Enviar)" & _
                            " SELECT SCOPE_IDENTITY()"


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdPedido", mintIdPedido)
        Command.Parameters.AddWithValue("Codigo", mstrCodigo)
        Command.Parameters.AddWithValue("Producto", mstrProducto)
        Command.Parameters.AddWithValue("Existencia", mdblExistencia)
        Command.Parameters.AddWithValue("Maximo", mdblMaximo)
        Command.Parameters.AddWithValue("Minimo", mdblMinimo)
        Command.Parameters.AddWithValue("Media", mdblMedia)
        Command.Parameters.AddWithValue("Pedir", mdblPedir)
        Command.Parameters.AddWithValue("Observaciones", mstrObservaciones)
        Command.Parameters.AddWithValue("Enviar", mintEnviar)
        
        cnConn.Open()
        IdPedidoDetalle = Convert.ToInt32(Command.ExecuteScalar)

        If IdPedidoDetalle > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el detalle del pedido ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
